package apiv1

import (
	"github.com/gin-gonic/gin"
	"go-shop-admin/internal/service"
	"go-shop-admin/pkg/e"
	"go-shop-admin/pkg/serializer"
	"net/http"
)

//角色表

func AuthRoleAdd(c *gin.Context) {
	var authRoleService *service.AuthRoleService

	if err := c.ShouldBind(&authRoleService); err != nil {
		c.JSON(http.StatusBadRequest, Validators(err))
		return
	}
	res := authRoleService.Add(c.Request.Context())
	c.JSON(http.StatusOK, res)

}

// AuthRoleUpdate 修改
func AuthRoleUpdate(c *gin.Context) {
	var authRoleService *service.AuthRoleService

	if err := c.ShouldBind(&authRoleService); err != nil {
		c.JSON(http.StatusBadRequest, Validators(err))
		return
	}

	id, _, err := GetRestfulApiId(c.Param("id"), 1)
	if err != nil {
		c.JSON(http.StatusBadRequest, serializer.NewResponse(e.InvalidParams, err.Error(), e.TipInvalidParams, nil))
	}

	res := authRoleService.Update(c.Request.Context(), id)
	c.JSON(http.StatusOK, res)

}

// AuthRoleShow 查看详情
func AuthRoleShow(c *gin.Context) {
	var authRoleService *service.AuthRoleService

	id, _, err := GetRestfulApiId(c.Param("id"), 1)
	if err != nil {
		c.JSON(http.StatusBadRequest, serializer.NewResponse(e.InvalidParams, err.Error(), e.TipInvalidParams, nil))
	}

	res := authRoleService.Show(c.Request.Context(), id)
	c.JSON(http.StatusOK, res)

}

// AuthRoleDelete  删除
func AuthRoleDelete(c *gin.Context) {
	_, ids, err := GetRestfulApiId(c.Param("ids"), 2)
	if err != nil {
		c.JSON(http.StatusBadRequest, serializer.NewResponse(e.InvalidParams, err.Error(), e.TipInvalidParams, nil))
	}
	var authRoleService *service.AuthRoleService
	res := authRoleService.Delete(c.Request.Context(), ids)
	c.JSON(http.StatusOK, res)

}
